//
//  DetailCollectionViewCell.m
//  B
//
//  Created by Sunpeng on 15/11/13.
//  Copyright © 2015年 wangzhan. All rights reserved.
//

#import "DetailCollectionViewCell.h"
#import <UIImageView+WebCache.h>
@implementation DetailCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
        
    }
    return self;
}

- (void)createSubViews{
    self.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 5;
    self.photo = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 0)];
    self.photo.contentMode = UIViewContentModeScaleAspectFill;
    self.photo.layer.masksToBounds = YES;
    [self addSubview:self.photo];
   
    
    self.text = [[UILabel alloc]initWithFrame:CGRectMake(self.photo.x, self.photo.height ,0,0)];
    self.text.numberOfLines = 0;
    [self addSubview:self.text];
    
    
    self.local_time = [[UILabel alloc]initWithFrame:CGRectMake(self.text.x, 0, self.contentView.width * 0.3, self.contentView.height * 0.1)];
    self.local_time.textColor = [UIColor lightGrayColor];
    self.local_time.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.local_time];
    
    
    self.local = [[UILabel alloc]init];
    self.local.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.local];
    
    
    self.shadow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"SPjourney_cell_shadow"]];
    [self addSubview:self.shadow];
    
    
    self.photo_bottom_cover = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"SPdestination_detail_photo_bottom_cover"]];
    [self addSubview:self.photo_bottom_cover];
    
    
    self.clock = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"SPclock_gray_big"]];
    [self addSubview:self.clock];
    
}

- (void)setData:(dayModel *)model{
    _model = model;
       
    
    [self.photo sd_setImageWithURL:[NSURL URLWithString:model.photo] placeholderImage:nil];
    if (model.photo.length != 0) {
        self.photo.size = CGSizeMake(WIDTH * 0.9, [model.photo_h integerValue]/([model.photo_w integerValue]/(WIDTH * 0.9)));
    }
    
    self.text.text = model.text;
    
    self.text.frame = CGRectMake(self.width * 0.025, self.photo.y + self.photo.height, WIDTH * 0.8, 0);
    [self.text sizeToFit];
    
    self.clock.frame = CGRectMake(self.width * 0.025, self.text.height + self.text.y, WIDTH*0.05, WIDTH*0.05);
    
    self.local_time.text = [model.local_time substringFromIndex:10];
    self.local_time.frame = CGRectMake(self.clock.width + self.clock.x, self.text.height + self.text.y, WIDTH * 0.3, WIDTH * 0.05);
    
    self.local.text = [NSString stringWithFormat:@"%@ %@",model.country,model.city];
    self.local.frame = CGRectMake(self.local_time.x + self.local_time.width, self.local_time.y, WIDTH * 0.5, WIDTH * 0.05);
    
    self.shadow.frame = CGRectMake(0, self.height-5, self.width, 5);
    self.photo_bottom_cover.frame = CGRectMake(0, self.photo.height-5, self.width, 5);
}

@end
